﻿<!DOCTYPE html>
<html>
<head>
    <title>{$platform.name}</title>
    <link href="/static/css/framework-font.css" rel="stylesheet"/>
    <script src="/static/js/jquery-2.1.1.js"></script>
    <script src="/static/bootstrap/js/bootstrap.js"></script>
    <link href="/static/bootstrap/css/bootstrap.min.css" rel="stylesheet"/>

    <script src="/static/js/jquery.cookie.js"></script>
    <link href="/static/css/framework-theme.css" rel="stylesheet"/>
    <script src="/static/js/framework-ui.js"></script>
    <script src="/static/js/framework-clientdata.js"></script>

    <!--弹框js-->
    <script src="/static/js/yii.js"></script>

    <!--引用layui弹框插件-->
    <script src="/static/layui/layui.all.js"></script>
    <script src="/static/layui/layui.js"></script>
    <link href="/static/layui/css/layui.css" rel="stylesheet"/>
    <script src="/static/layui/lay/modules/layer.js"></script>



        {if condition="$swidthStyle eq 0"}
    <link href="/static/css/pattern/public.css" rel="stylesheet"/>
    {else/}
        {if condition="$swidthStyle eq 0"}
    <link href="/static/css/pattern/public.css" rel="stylesheet"/>
    {else/}
    <link href="/static/css/default/public.css" rel="stylesheet"/>
    {/if}
    {/if}
</head>
<body>

<style>
    html, body{background-color: #fff!important;}
    .new_main{border-top:1px solid #ccc}
    .batch{line-height:35px;}
</style>

<div class="newtest">

    <div class="container new_serach">
        {volist name="powerList" id="vo"}
        <a class="btn btn-primary btn-sm" href="{$vo['url']}">{$vo.name}</a>
        {/volist}
    </div>

    <div class="container new_serach">

        <span> 关键字：</span>
        <div class="layui-inline">
            <input class="form-control serach_key" name="keyword"  type="text">
        </div>
        <span> 状态：</span>
        <div class="layui-inline layui-form"  style="width:80px;">
            <select name="status" lay-filter="status">
                <option value="0" >全部</option>
                <option value="1" >启用</option>
                <option value="2" >禁用</option>
            </select>
        </div>
        <button class="layui-btn layui-btn-sm" data-type="reload">搜索</button>


    </div>

    <div class="new_main">

        <table class="layui-hide" id="demo" lay-filter="demo"></table>

        <script type="text/html" id="barDemo">
            <a class="btn-sm btn-primary" lay-event="add">修改</a>
            <a class="btn-sm btn-danger" lay-event="del">删除</a>
        </script>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <a class=" layui-btn-sm layui-btn" href="{:URL('admin/ptt/index')}">内容管理</a>
                <a class=" layui-btn-sm layui-btn" href="{:URL('admin/ptt/classify')}?role_id={$role_id}">分类管理</a>
                <a class="layui-btn-sm layui-btn" lay-event="add">添加分类</a>
                <button class="layui-btn layui-btn-sm layui-btn-danger" lay-event="getCheckLength">批量删除</button>
            </div>
        </script>

        <script type="text/html" id="switchTpl">
            <!--启用审核操作-->
            <input type="checkbox" name="status" value="{{d.id}}" lay-skin="switch" lay-text="启用|禁用" lay-filter="sexDemo" {{ d.status == 1 ? 'checked' : '' }}>
        </script>


    </div>
</div>


</body>
<script src="/static/js/index.js"></script>
<script src="/static/js/indextab.js"></script>
<script src="/static/js/pace.min.js"></script>
<script>
    //全选操作

    var modal = new yii.modal();

    layui.use(['form', 'jquery', 'layer', 'laydate','table'], function () { //独立版的layer无需执行这一句
        var $ = layui.jquery, layer = layui.layer;
        var form = layui.form;
        var laydate = layui.laydate;
        var table = layui.table //表格
        //日期范围
        laydate.render({
            elem: '#test6'
            , range: true
        });

        var status = 0;
        form.on('select(status)',function (data) {
            status = data.value;
        });



        var url = "{:URL('admin/ptt/classify')}";
        //搜索操作
        $('.layui-btn').click(function () {
            var keyword = $('input[name="keyword"]').val();
            var where = {keyword:keyword,status:status};
            search(table,url,where)
        });

        //列表
        var where = {type:'list'};
        var title = "社区内容列表";
        var cols = [[
            {type: 'checkbox', fixed: 'left'}
            ,{field: 'id', title: 'ID',  sort: true, fixed: 'left',width:80, align:'center'}
            ,{field: 'name', title: '分类名称', align:'center'}
            ,{field: 'status', title: '状态',templet: '#switchTpl', unresize: true, align:'center'}
            ,{field: 'sort', title: '排序',align:'center',edit: 'number',width:80,sort: true}
            ,{field: 'addtime', title: '添加时间', align:'center',sort: true}
            ,{fixed: 'right',title: '操作', width:300, align:'center', toolbar: '#barDemo'}
        ]];
        showlist(table,url,where,title,cols);

        //监听单元格编辑
        table.on('edit(demo)', function(obj){
            var value = obj.value; //得到修改后的值
            var id = obj.data.id;
            $.ajax({
                type: "post",
                url: "/common/Common/updateSort",
                data: {id: id,table:'admin_ptt',value:value},
                dataType: "json",
                success: function (data) {
                    if(data.code!=0){
                        layer.alert(data.msg);
                    }
                }
            });
        });

        //监听启用禁用操作
        form.on('switch(sexDemo)', function(obj){
            var id = this.value;
            var state = obj.elem.checked;
            let url = "{:URL('common/together/clickStatus')}";

            if (state == true) {
                let data = {id:id,status:1,table:'admin_ptt'}
                //上线
                publicClickStatus(url,data);
            } else {
                let data = {id:id,status:2,table:'admin_ptt'}
                //下线
                publicClickStatus(url,data);
            }
        });


        //监听行工具事件
        table.on('tool(demo)', function(obj) {
            var id = obj.data.id;
            switch (obj.event) {
                case 'del':
                    layer.confirm('是否确定操作?', function (index) {
                        let url="{:URL('admin/ptt/delClassify')}";
                        let data = {id:id};
                        publicDel(table,url,data,obj,index);
                    });
                    break;
                case 'add':
                    modal.initialization({
                        url: "{:URL('admin/ptt/classifyDetail')}",
                        type: "post",
                        data:{
                            type:'detail',
                            id:id,
                            role_id:"{$role_id}"
                        }
                    });
                    break;
            }
        });


        //头工具栏事件
        table.on('toolbar(demo)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'getCheckLength':
                    var data = checkStatus.data;
                    var id=[];
                    for (var i = 0; i < data.length; i++) {
                        id[i] = data[i].id;
                    }
                    if(id.length==0){
                        layer.alert("请选择需操作的数据");return;
                    }
                    layer.confirm('是否确定操作?', function(index){
                        let url="{:URL('admin/ptt/delClassify')}";
                        let where = {id:id};
                        publicDel(table,url,where,obj,index,1);
                    });
                    break;
                case 'add':
                    modal.initialization({
                        url: "{:URL('admin/ptt/classifyDetail')}",
                        type: "post",
                        data:{
                            type:'detail',
                            role_id:"{$role_id}"
                        }
                    });

            };
        });



    });

</script>

</html>
